package com.tql.test_04;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
/*
* Callable 和Runnable的区别
* 1.可以有返回值
* 2.可以抛出异常
* */
public class CallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallableTest1 callableTest1=new CallableTest1();
        //FutureTask 是Runnable接口的实现类，坐中间商使用，起连接作用，因为Thread处理的是runable接口
        FutureTask futureTask=new FutureTask(callableTest1);
        new Thread(futureTask,"a").start();
        //get方法可能发生阻塞
        System.out.println(futureTask.get());
    }
}
class CallableTest1 implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println("helo");
        return "hello";
    }
}
